package com.mathassistant.client.view;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RichTextArea;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.mathassistant.client.presenter.EditorPresenter.Display;
import com.mathassistant.client.resource.RichTextToolbar;

public class EditorView extends DialogBox implements Display{
	private VerticalPanel panelContend;
	private Button buttonSave;
	private Button buttonCancel;
	private RichTextArea area;
	private RichTextToolbar toolBar;
	void init()
	{
		panelContend = new VerticalPanel();
		
		buttonSave = new Button("Lưu");
		buttonCancel = new Button("Hủy");
		area = new RichTextArea();
		area.setSize("700px", "500px");
		toolBar = new RichTextToolbar(area);
		toolBar.setWidth("100%");
		
		Grid grid = new Grid(2, 1);
		grid.setWidget(0, 0, toolBar);
		grid.setWidget(1, 0, area);
		panelContend.add(grid);
		
		HorizontalPanel hPanel = new HorizontalPanel();
		hPanel.setSpacing(2);
		hPanel.add(buttonSave);
		hPanel.add(buttonCancel);
				
		panelContend.add(hPanel);
		this.setWidget(panelContend);
		
	}
	
	public EditorView(boolean autoHide)
	{
		super(autoHide);
		init();	
		this.setAnimationEnabled(true);
		this.setGlassEnabled(true);		
		this.center();		
		showDialog();
	}
	@Override
	public HasClickHandlers getSaveButton() {
		// TODO Auto-generated method stub
		return this.buttonSave;
	}
	@Override
	public HasClickHandlers getCancelButton() {
		// TODO Auto-generated method stub
		return this.buttonCancel;
	}
	@Override
	public String getContentHtml() {
		// TODO Auto-generated method stub
		return this.area.getHTML();
	}
	
	@Override
	public void hideDialog() {
		// TODO Auto-generated method stub
		this.hide();
	}
	@Override
	public void showDialog() {
		// TODO Auto-generated method stub
		this.show();
	}
	@Override
	public void setContentHtml(String content) {
		// TODO Auto-generated method stub
		area.setHTML(content);
	}
}
